package org.ming.ticketSellingSystem.framework.starter.bases.config;

import org.ming.ticketSellingSystem.framework.starter.bases.ApplicationContextHolder;
import org.ming.ticketSellingSystem.framework.starter.bases.init.ApplicationContentPostProcessor;
import org.ming.ticketSellingSystem.framework.starter.bases.safa.FastJsonSafaMode;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;

/**
 * 应用基础自动装配
 */
public class ApplicationBaseAutoConfiguration {
    @Bean
    @ConditionalOnMissingBean //当Spring中不存在该类型的时候才会创建这Bean
    public ApplicationContextHolder congoApplicationContextHolder(){
        return new ApplicationContextHolder();
    }

    @Bean
    @ConditionalOnMissingBean
    public ApplicationContentPostProcessor congoApplicationContentPostProcessor(ApplicationContext applicationContext){
        return new ApplicationContentPostProcessor(applicationContext);
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(value = "framework.fastjson.safa-mode",havingValue = "true") //当application中有字段"framework.fastjson.safa-mode",同时value = true的时候才会注册该Bean
    public FastJsonSafaMode congoFastJsonSafaMode(){
        return new FastJsonSafaMode();
    }

}
